<?php
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'DAO' . DIRECTORY_SEPARATOR . 'AppDAO.php';
require_once WEB_MODEL_DIR . DIRECTORY_SEPARATOR . 'DAO' . DIRECTORY_SEPARATOR . 'AppMessageDAO.php';
class AppMessageService {

    public function getAllAppMessage($context, $result, $start, $limit) {
        $appMessageArr = null;
        try {
            $AppMessageDAO = new AppMessageDAO($context);

            $appMessageArr = $AppMessageDAO -> getAllAppMessage($start, $limit);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found");
                $context -> logError("ERR01", "No App Found Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appMessageArr;
    }
    
	public function getAppMessageByAppId($context, $result, $id) {
        $appMessageArr = null;
        try {
            $AppMessageDAO = new AppMessageDAO($context);

            $appMessageArr = $AppMessageDAO -> getAppMessageByAppId($id);
            
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appMessageArr;
    }

    public function countAppMessage($context, $result) {
        $total = 0;
        try {
			$AppMessageDAO = new AppMessageDAO($context);

            $total = $AppMessageDAO -> countAppMessage();
            
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $total;
    }
    
	public function getAppMessageById($context, $result, $id) {
        $appMessageArr = null;
        try {
            $gameMessageDAO = new AppMessageDAO($context);

            $appMessageArr = $gameMessageDAO -> getAppMessageById($id);
            if (isset($appArr) && !empty($appArr)) {
                $result -> setSuccess();
            } else {
                $result -> setFailed("ERR01", "No App Found By Id : " . $id);
                $context -> logError("ERR01", "No App Found By Id : " . $id . " Call By " . __METHOD__ . " ON " . __CLASS__);
            }
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }

        return $appMessageArr;
    }
    
	public function insertAppMessage($context, $result,$param) {
        $appMessageArr = null;
        try {
            $gameMessageDAO = new AppMessageDAO($context);

            $appMessageArr = $gameMessageDAO -> insertAppMessage($param);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
        return $appMessageArr;
    }
    
	public function updateAppMessage($context, $result,$param) {
        $appMessageArr = null;
        try {
            $gameMessageDAO = new AppMessageDAO($context);

            $appMessageArr = $gameMessageDAO -> updateAppMessage($param);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
        return $appMessageArr;
    }
    
	public function deleteAppMessage($context, $result, $id) {
        try {

            $gameMessageDAO = new AppMessageDAO($context);

            $gameMessageDAO -> deleteAppMessage($id);
        } catch (Exception $e) {
            $result -> setException($e);
            $context -> logException($e);
        }
    }
}
?>